package com.liangzdemo.observertwo;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.liangzdemo.R;

import java.util.ArrayList;
import java.util.List;

public class Main3Activity extends AppCompatActivity implements View.OnClickListener{

    private Button btnAddObserver;
    private Button btnChangeData;
    private List listView;
    private MyPerson observable;
    private List<MyObserver> myObservers;
    private MyObserver myObserver;
    private int i;


    private Handler handler = new Handler() {
//        public void handleMessage(android.os.Message msg) {
//            MyListAdapter myListAdapter = new MyListAdapter(Main3Activity.this,
//                    myObservers);
            //listview.setAdapter(myListAdapter);
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        btnAddObserver = (Button)findViewById(R.id.btn_add_observer);
        btnChangeData = (Button)findViewById(R.id.btn_change_data);
       // listView = getListView();


        observable = new MyPerson();
        myObservers = new ArrayList<MyObserver>();

        btnAddObserver.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.btn_add_observer:
                myObserver = new MyObserver(i);
                i++;
                observable.addObserver(myObserver);
                myObservers.add(myObserver);
                handler.sendEmptyMessage(0);
                break;
            case R.id.btn_change_data:
                break;
        }
    }
}
